<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>上传照片</title>
    
</head>
<body>
  
  <form action="/ajaxUpload" enctype="multipart/form-data" id="form" method="POST">
      姓名：<input type="text" name="username" id=""><br>
      年龄：<input type="text" name="age" id=""><br>
      <br>
      本人照片：<input type="file" name="img" id="" value="选择照片"><br><br>
      <input type="button" value="确认提交" name="btn" id="btn">
  </form>
</body>
<script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.min.js"></script>
<script>
  $('#btn').click(function () {
    // 利用formData将整个表单数据打包
    var inpData = new FormData(document.getElementById('form'));
    $.ajax({
      url: '/ajaxUpload',
      type: 'post',
      contentType: false,
      data: inpData, // 打成的数据包可以直接通过send发送
      processData: false,
      success: function (data) {
        if (data) {
          console.log('ajax上传图片：成功');
        } else {
          console.log('ajax上传图片：失败');
        }
      }
    });
  });
</script>
</html>